package de.fhhannover.inform.hnefatafl.gui;

import java.awt.Dimension;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

public class LogPanel extends JPanel{
	
	private static final long serialVersionUID = 1L;
	
	JTextArea   		logger;
	JScrollPane 		logScroller;
	File				file;
	FileReader			fr;
	
	public LogPanel() throws IOException{
		
		file = new File("Hnefatafl.log");
		
		if(file.exists() == false){
			file.createNewFile();
		}
		
		
		
		logger = new JTextArea(4,50);
		logger.setText("Angreifer (Schwarz) faengt an.\n");
		logger.setEditable(false);
		logScroller = new JScrollPane(logger);
		logScroller.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
		this.add(logScroller);
		this.setPreferredSize(new Dimension(600,40));
	}
	
	public void readFromLog(){
		try {
			fr = new FileReader(file);
			logger.read(fr, "");
			logger.setCaretPosition(logger.getText().length());
			fr.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}


